<template>
	<view>
		
		<view class="louis-lpadding louis-center"><button @tap="upimges" size="default" type="success">上传图片</button></view>

		<view v-for="(item, index) in list" :key="index" class="imgbox">
			<image id="imges" :src="item.main_img" mode=""></image>
			<view class="louis-center">{{ item.name }}</view>
		</view>

		
		<view class="louis-space-between">
			 <view @tap="pagenum-=1;geinfo()" class="louis-bg-fff">
			 	上一页
			 </view>
			 <view @tap="pagenum+=1;geinfo()" class="louis-bg-fff">
			 	下一页
			 </view>
		</view>
		
	</view>
</template>

<script>
// import uniPagination from '@/components/uni-pagination/uni-pagination.vue';
export default {
	data() {
		return {
			inputs: '',
			list: [],
			pagenum: 1,
			total: 100
		};
	},
	mounted() {
		this.geinfo();
	},
	// components: { uniPagination },
	methods: {
		changenum(e) {
			console.log(e);
			this.pagenum = e.current;
			this.geinfo();
		},
		geinfo() {
			this.$HTTP({
				url: '/verify/verify_code_controller/get_file_it',
				method: 'POST',
				data: {
					page: this.pagenum,
					pagesize: 6,
					name: ''
				}
			})
				.then(res => {
					console.log(res);
					if (res.data.code == 200) {
						this.list = res.data.data.data;
						this.total = res.data.data.total;
					}
				})
				.catch(err => {
					uni.showToast({
						icon: 'none',
						title: '失败'
					});
				});
		},
		upimges() {
			if (this.inputs == '') {
				this.inputs = Date.parse(new Date()).toString();
			}

			uni.chooseImage({
				success: chooseImageRes => {
					console.log(chooseImageRes)
					
					const tempFilePaths = chooseImageRes.tempFiles;
					uni.uploadFile({
						url: 'api/verify/verify_code_controller/upload_file', //仅为示例，非真实的接口地址
						filePath: tempFilePaths[0].path,
						name: 'file',
						success: uploadFileRes => {
							let uploadFileResdata = JSON.parse(uploadFileRes.data);
							console.log(uploadFileResdata);
							uni.showToast({
								icon: 'none',
								title: uploadFileResdata.message
							});
							let that = this;
							this.$HTTP({
								url: '/verify/verify_code_controller/save_user_card',
								method: 'POST',
								data: {
									main_img: uploadFileResdata.main_img,
									name: that.inputs
								}
							})
								.then(res => {
									console.log(res);
									if (res.data.code == 200) {
										uni.showToast({
											icon: 'none',
											title: '上传成功'
										});
										this.geinfo();
									}
									this.inputs = '';
								})
								.catch(err => {
									uni.showToast({
										icon: 'none',
										title: '失败'
									});
								});
						}
					});
				}
			});
		}
	}
};
</script>

<style scoped lang="less">
.imgbox {
	display: inline-block;
	// margin: 10rpx;
	padding: 10px;
	width: 40vw;
	border: 1px solid #cccccc;
	border-radius: 10px;
	margin: 1vw;
	background-color: rgba(255,255,255,0.5)
}

#imges {
	width: 100%;
	height: 40vw;
}
.bototm {
	position: absolute;
	bottom: 10rpx;
	display: flex;
	justify-content: center;
	width: 100%;
}

</style>
